/*
 * Copyright 2018-10-1 20:47:06 The JA-SIG Collaborative. All rights reserved.
 * distributed with thi file and available online at
 */
package com.lap.scp.erp.controller;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.lap.scd.commons.result.Resp;
import com.lap.scp.erp.ao.PaymentAO;
import com.lap.scp.erp.domain.PaymentDO;
import com.lap.scp.erp.query.PaymentQueryVO;

/**
 * <pre>
 *  开支控制对象，提供 其他成本 新增,编辑,查询等操作。
 *  控制层统一命名规则：
 *  进入新增 	add,
 *  增加保存 	save,
 *  进入修改 	edit,
 *  修改保存 	update,
 *  查询分页 	queryPage,
 *  根据ID查询 	get,
 *  删除 		deleteById
 *
 * </pre>
 * 
 * @author 劳水生 Exp
 * @Date 2018-10-1 20:47:06
 * @since 2.0.0
 */
@Controller
@RequestMapping("payment")
public class PaymentController {
	/**
	 * 其他成本应用流程对象
	 */
	@Resource
	private PaymentAO paymentAO;

	/**
	 * <pre>
	 * 进入其他开支新增页面
	 * </pre>
	 * 
	 * @return
	 */
	@GetMapping(value = "addOther")
	public ModelAndView addOther(Integer contractId) {
		ModelAndView andView = new ModelAndView("erp/otherEdit");
		PaymentDO paymentDO = new PaymentDO();
		paymentDO.setContractId(contractId);
		andView.addObject("paymentDO", paymentDO);
		return andView;
	}

	/**
	 * <pre>
	 * 进入其他开支编辑页面
	 * </pre>
	 * 
	 * @return
	 */
	@GetMapping(value = "editOther")
	public ModelAndView editOther(Integer paymentId) {
		ModelAndView andView = new ModelAndView("erp/otherEdit");
		Resp<PaymentDO> resp = paymentAO.queryById(paymentId);
		andView.addObject("paymentDO", resp.getData());
		return andView;
	}

	/**
	 * <pre>
	 * 新增开支信息
	 * </pre>
	 * 
	 * @param paymentDO
	 * @return
	 */
	@PostMapping(value = "add")
	@ResponseBody
	public Resp<PaymentDO> add(PaymentDO paymentDO) {
		return paymentAO.insertPayment(paymentDO);
	}

	/**
	 * <pre>
	 * 修改开支信息
	 * </pre>
	 * 
	 * @param paymentDO
	 * @return
	 */
	@PostMapping(value = "edit")
	@ResponseBody
	public Resp<Integer> edit(PaymentDO paymentDO) {
		return paymentAO.updatePayment(paymentDO);
	}

	/**
	 * <pre>
	 * 根据ID删除开支
	 * </pre>
	 * 
	 * @param paymentId
	 * @param map
	 * @param attributes
	 * @return
	 */
	@GetMapping(value = "delete/{paymentId}")
	@ResponseBody
	public Resp<Integer> deleteById(@PathVariable Integer paymentId) {
		return paymentAO.deleteById(paymentId);
	}

	/**
	 * <pre>
	 * 开支明细
	 * </pre>
	 * 
	 * @param queryVO
	 * @return
	 */
	@GetMapping(value = "queryDetail")
	public ModelAndView queryDetail(PaymentQueryVO queryVO) {
		ModelAndView andView = new ModelAndView();
		Resp<List<PaymentDO>> resp = paymentAO.queryDetail(queryVO);
		if (resp.isSuccess()) {
			andView.setViewName("erp/paymentDetail");
			andView.addObject("list", resp.getData());
			andView.addObject("queryVO", queryVO);
		} else {
			andView.setViewName("error");
		}
		return andView;
	}

}
